// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Buffers;
using System.Runtime.CompilerServices;

namespace eNets.IO.Memorizer;

public static class MemoryPoolProvider
{
    public static int GetBlockSize()
    {
        return MemoryPoolConfig.BlockSize;
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static MemoryPool<T> Create<T>()
    {
#if DEBUG
        return new DiagnosticMemoryPool<T>(CreatePinnedBlockMemoryPool<T>());
#else
        return CreatePinnedBlockMemoryPool<T>();
#endif
    }

    private static MemoryPool<T> CreatePinnedBlockMemoryPool<T>()
    {
        return new PinnedBlockMemoryPool<T>();
    }

    public static MemoryPool<T> ShareMemoryPool<T>()
    {
        return SharedMemoryPool<T>.shared;
    }
}